﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CoVanHocTapData.Entities;

using CoVanHocTapData.Concretes;
using CoVanHocTapData.Interface;


namespace CoVanHocTapProject.Infrastructure
{
    public class Publics
    {
        #region repos
        static IHocKyRepository hocKyRepos = new HocKyRepository();
        #endregion

        public static HocKy hocKyHienTai
        {
            get {
                HocKy hk;
                if (HttpContext.Current.Application["HocKyHienTai"] == null)
                {
                    hk = hocKyRepos.LayHocKyHienTai();
                    HttpContext.Current.Application["HocKyHienTai"] = hk;
                }
                else
                    hk = HttpContext.Current.Application["HocKyHienTai"] as HocKy;
                return hk;
            }
            
        }

        public static SinhVien sinhVienDangNhap
        {
            get
            {
                if (HttpContext.Current.Session["SinhVienDN"] == null)
                    return null;
                return (SinhVien)(HttpContext.Current.Session["SinhVienDN"]);
            }
            set
            {
                HttpContext.Current.Session["SinhVienDN"] = value;
            }
        }

        public static bool IsLogin()
        {
            return (Publics.sinhVienDangNhap != null);
        }

        public static void ClearSession()
        {
            HttpContext.Current.Session.Clear();
        }

        public static void Logout()
        {
            Publics.sinhVienDangNhap = null;            
        }

        public static string ClientMessageBox(string msg)
        {
            return "<script language='javascript'>alert('" + msg.Replace("\r\n", "\n").Replace("\n", "\\n") + "');</script>";
        }
    }
}